package biz.datalk.industrialland.common.pojo.po;

import biz.datalk.industrialland.common.def.CommonConstant;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * @author tarofang@163.com
 * @date 2019年08月12日
 */
@SuppressWarnings("unused")
public class BasePO {

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Integer pageNumber;
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Integer pageSize;

    /**
     * 查询字段, 使用英文逗号","分隔
     * {@link CommonConstant#QUERY_FIELDS_SEPARATOR }
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String queryFields;

    public String getQueryFields() {
        return queryFields;
    }

    //@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    //public String[] getQueryFieldsArr() {
    @JsonIgnore
    public String[] queryFieldsArr() {
        if (this.queryFields == null) {
            return new String[0];
        }
        return StringUtils.splitByWholeSeparatorPreserveAllTokens(this.queryFields, CommonConstant.QUERY_FIELDS_SEPARATOR);
    }

    public void setQueryFields(String queryFields) {
        this.queryFields = queryFields;
    }

    public Integer getPageNumber() {
        return pageNumber == null ? 1 : pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getPageSize() {
        return pageSize == null ? 10 : pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}
